from UI_web_jd.contig.Base import Base
from selenium.webdriver.common.by import By
import time
class Page(Base):
    # 通过CSS选择器定位用户登录按钮  class="link-login"
    loginan_loc = (By.CLASS_NAME,'link-login')
    def loginan(self):
        self.click(self.loginan_loc)
    #点击短信登录 id="sms-login"
    duanxin_loc = (By.ID,'sms-login')
    def duanxin(self):
        self.click(self.duanxin_loc)
    #输入手机号 id="mobile-number"
    sjh_loc = (By.ID,'mobile-number')
    def sjh(self):
        self.send_keys(self.sjh_loc,'18615488780')
    #点击获取验证码  id="send-sms-code-btn"
    yzm_loc = (By.ID,'send-sms-code-btn')
    def yzm(self):
        self.click(self.yzm_loc)
    #点击登录 id="sms-login-submit"
    login_loc = (By.ID,'sms-login-submit')
    def login(self):
        self.click(self.login_loc)
    #定位首页的商品搜索输入框   //*[@id="key"]  智能手机
    sousuo_loc = (By.XPATH,'//*[@id="key"]')
    def sousuo(self):
        self.send_keys(self.sousuo_loc,"智能手机")
    #点击搜索 class="btn"
    djsousuo_loc = (By.CLASS_NAME,'btn')
    def djsousuo(self):
        self.click(self.djsousuo_loc)
    #断言 class="search_key"
    dy_text = (By.CLASS_NAME,'search_key')
    def dy(self):
        print(self.text(self.dy_text))
        assert "智能手机" in self.text(self.dy_text)
    #第一个商品价格 class="p-price"
    #第一个商品名称 /html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1]/div[3]/a/em/text()[1]
    jg1_text = (By.CLASS_NAME,'p-price')
    def jg1(self):
        print(self.text(self.jg1_text))
    name1_text = (By.XPATH,'/html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1]/div[3]/a/em/text()[1]')
    def name1(self):
        print(self.text(self.name1_text))
    #第二个商品价格 class="price"
    #第二个商品名称 //*[@id="shop_list"]/li[2]/div/div[2]/a/div[2]
    jg2_text = (By.CLASS_NAME,'price')
    def jg2(self):
        print(self.text(self.jg2_text))
    name2_text = (By.XPATH,'//*[@id="shop_list"]/li[2]/div/div[2]/a/div[2]')
    def name2(self):
        print(self.text(self.name2_text))
    #第三个商品价格 class="p-price"
    #第三个商品名称 //*[@id="shop_list"]/li[2]/div/div[2]/a/div[3]
    jg3_text = (By.CLASS_NAME,'price')
    def jg3(self):
        print(self.text(self.jg3_text))
    name3_text = (By.XPATH,'/html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1]/div[3]/a/em/text()[1]')
    def name3(self):
        print(self.text(self.name3_text))
    # 第四个商品价格 class="p-price"
    # 第四个商品名称 /html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1
    jg4_text = (By.CLASS_NAME,'price')
    def jg4(self):
        print(self.text(self.jg4_text))
    name4_text = (By.XPATH,'/html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1]/div[3]/a/em/text()[1]')
    def name4(self):
        print(self.text(self.name4_text))
    #第五个商品价格 class="p-price"
    #第五个商品名称 /html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1
    jg5_text = (By.CLASS_NAME,'price')
    def jg5(self):
        print(self.text(self.jg5_text))
    name5_text = (By.XPATH,'/html/body/div[6]/div[2]/div[2]/div[2]/div/ul/li[1]/div[3]/a/em/text()[1]')
    def name5(self):
        print(self.text(self.name5_text))
    def test_jd(self):
        self.open("https://www.jd.com/")
        self.loginan()

        self.duanxin()
        self.sjh()
        time.sleep(3)
        self.yzm()
        time.sleep(3)
        self.login()
        self.sousuo()
        self.djsousuo()
        self.qiehuan()
        self.jietu()
        self.dy()